package multiDemo;

import java.io.IOException;
import java.net.DatagramPacket;
import java.net.InetAddress;
import java.net.MulticastSocket;
import java.net.UnknownHostException;

public class SendDemo {
    public static void main(String[] args) throws IOException {
        //组播
        //1.创建组播对象
        MulticastSocket ms  = new MulticastSocket();
        //1.1将本机地址添加到组播地址中
        InetAddress address = InetAddress.getByName("127.0.0.1");
        //2.打包数据
        String str = "你好";
        byte[] bytes = str.getBytes();
        int port = 1000;
        //4.发送数据
        DatagramPacket dp = new DatagramPacket(bytes,bytes.length,address,port);
        ms.send(dp);

        //释放资源
        ms.close();
    }
}
